package com.hnxxxy.workshop.controller;


import com.hnxxxy.workshop.request.ComponentsPageRequest;
import com.hnxxxy.workshop.request.ComponentsRequest;
import com.hnxxxy.workshop.request.DepotPageRequest;
import com.hnxxxy.workshop.request.DepotRequest;
import com.hnxxxy.workshop.service.ComponentsService;
import com.hnxxxy.workshop.utils.R;
import com.hnxxxy.workshop.vo.ComponentsVO;
import com.hnxxxy.workshop.vo.DepotVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>
 * 零件 前端控制器
 * </p>
 *
 * @author zqh
 * @since 2022-05-09
 */
@RestController
@RequestMapping("/components")
@Api(value = "ComponentsController", tags = {"零件模块"})
public class ComponentsController {

    @Resource
    private ComponentsService componentsService;

    @PostMapping("/add")
    @ApiOperation(value = "创建零件")
    public R add(@ApiParam("零件对象") @RequestBody ComponentsRequest componentsRequest){
        componentsService.add(componentsRequest);
        return R.buildSuccess();
    }

    @GetMapping("/remove/{id}")
    @ApiOperation(value = "删除零件")
    public R deleteById(@ApiParam(value = "零件id",required = true)
                        @PathVariable("id") int id){
        componentsService.deleteById(id);
        return R.buildSuccess();
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改零件")
    public R update( @ApiParam("零件对象")
                     @RequestBody ComponentsRequest componentsRequest){
        componentsService.update(componentsRequest);
        return R.buildSuccess();
    }

    @GetMapping("/findById/{id}")
    @ApiOperation(value = "根据id查询零件信息")
    public R findByIdComponents(@ApiParam(value = "零件id",required = true)
                           @PathVariable("id") int id ){
        ComponentsVO componentsVO = componentsService.findByIdComponents(id);
        return R.buildSuccess(componentsVO);
    }

    @PostMapping("/page")
    @ApiOperation(value = "分页查询全部零件")
    public R findByIdFactory(@ApiParam(value = "分页对象",required = true)
                             @RequestBody ComponentsPageRequest componentsPageRequest){
        Map<String,Object> pageResult = componentsService.page(componentsPageRequest);
        return R.buildSuccess(pageResult);
    }

}

